#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2014-08-18 15:48:48
# @Author  : shitao.tommy (hero007asd@gmail.com)
# @Link    : http://example.org
# @Version : $Id$
import hashlib

def md5(param):
    m = hashlib.md5()
    m.update(str(param))
    return m.hexdigest()


def password(param):
    m = hashlib.md5()
    m.update(str(param))
    return m.hexdigest()

def base64_url_safe(stg):
    '''base64加密'''
    try:
        result = base64.urlsafe_b64encode(uuid.uuid3(uuid.NAMESPACE_DNS,stg).bytes)
    except:
        now = str(time.time()) + str(random.random())
        result = base64.urlsafe_b64encode(uuid.uuid3(uuid.NAMESPACE_DNS,now).bytes)
    return result


import crypt
import random,string
def __getsalt(chars = string.letters+string.digits):
    '''获取随机2位字符'''
    return random.choice(chars)+random.choice(chars)

def crypt_str(stg):
    return crypt.crypt(stg, __getsalt())

# salt = getsalt()
# chars = string.letters + string.digits
# print chars
# print salt
# print crypt.crypt('1000000000000000020183723091312312',salt)
